@extends('layouts.master3')
@section('title')
{{"千里码-人才服务"}}
@stop

@section('css')
<link rel="stylesheet" href="http://www.qlcoder.com/css/bootstrap-datetimepicker.min.css"/>
<link rel="stylesheet" href="/css/talents.css">
@stop

@section('content')
<input type="hidden" id="_token" value="{{csrf_token()}}" />
<input type="hidden" id="userid" value="{{$userid2}}" />
<div class="contain">
    <div class="talents-sidebar inline">
        <div class="talents-title">
<?php if($isself) echo '<a href="/talent/preview" class="title tab" data-target1="interview-resume">我的简历</a>';
	else echo '<a href="/talent/preview?userid='.$userid2.'" class="title tab" data-target1="interview-resume">我的简历</a>';
?>	
        </div>
        <!--<div class="talents-title">
            <a href="javascript:;" class="title tab active" data-target1="interview-consult">面试咨询</a>
        </div>-->
        <div class="talents-title">
            <a href="javascript:;" class="title tab active" id="myWork" data-target1="interview-work">推荐工作 </a>
            <ul>
			<li><a href="javascript:;" id="myInvite" class="tab invit" data-mark="invit" data-target1="interview" data-url="/talent/invit"><?php if($all_not_read>0) echo '<span class="badge">'.$all_not_read.'</span>';?>面试邀请 <span class="res"><?php echo $not_cnt; ?>/<?php echo $all_cnt;?></span></a></li>
				<li><a href="javascript:;" id="myInterview" class="tab interview" data-mark="interview"  data-target1="interview" data-url="/talent/interview"><?php if($interview_not_read>0) echo '<span class="badge">'.$interview_not_read.'</span>';?>面试 <span class="res"><?php echo $interview_cnt; ?></span></a></li>
				<li><a href="javascript:;" id="myResult" class="tab result" data-mark="result" data-target1="interview" data-url="/talent/result"><?php if($result_not_read>0) echo '<span class="badge">'.$result_not_read.'</span>';?>面试结果 <span class="res"><?php echo $result_cnt; ?></span></a></li>
            </ul>
        </div>
    </div>
    <div class="talents-inbox">
        <section class="section-tab interview-consult">
            <div class="qldada consult">
				<div class="tip">这里填说明</div>
				<!--当选择完时间后  添加refuse  class  和disabled属性-->
                       <!-- <button type="button"  class="interview inline" data-toggle="modal" data-target="#myModal">面试咨询</button>-->
                        <div class="task-shadow none"></div>
                        <!--咨询时间modal S-->
                        <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                            <div class="modal-dialog">
                                <div class="modal-content">
                                    <div class="modal-header">
                                        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                                        <h4 class="modal-title" id="myModalLabel">选择咨询时间</h4>
                                    </div>
                                    <div class="modal-body">
                                        <input  class="date-input form-control" placeholder="咨询日期"  name="data" style="display:inline-block;width:30%;outline:none;" />
                                        <select name="time" id="" class="form-control" style="display:inline-block;width:30%;">
                                            <option value="09:00-11:00">09:00-11:00</option>
                                            <option value="11:00-13:00">11:00-13:00</option>
                                            <option value="13:00-15:00">13:00-15:00</option>
                                            <option value="15:00-17:00">15:00-17:00</option>
                                        </select>
                                    </div>
                                    <div class="modal-footer">
                                        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                                        <button type="button" class="btn btn-primary">确定</button>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <!--咨询时间modal E-->
            </div>
        </section>
        <section class="section-tab interview-work">
			<div class="qldada consult">
				<form method="post" action="/talent/commit_invit?userid={{$userid2}}&isneed=<?php if($isneed) echo "0"; else echo "1"?>">
				<input type="hidden" name="_token" value="{{csrf_token()}}" />
				<h3>你好，{{$user->name}}</h3>
				<?php if(!$isneed) echo '<div class="tip">';?> <?php if(!$isneed && $userword!=NULL) echo $userword->words;?><?php if(!$isneed) echo '</div>
		<a class="interview" href="/talent/preview">完善简历并提交申请</a> '; 
	else echo '<div class="tip">你已提交申请，@千里码官方正在火速为你推荐工作，请注意提醒</div>';
?>
				</form>
            </div>
        </section>
        <section class="section-tab interview">
            <div class="sec-left "> </div>
            <div class="sec-right "></div>
        </section>
		<!--resumeModal S-->
            <div class="modal fade" id="resumeModal" tabindex="-1" role="dialog" aria-labelledby="resumeModalLabel" aria-hidden="true">
                <div class="modal-dialog">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                            <h4 class="modal-title" id="resumeModalLabel">完善简历</h4>
                        </div>
                        <div class="modal-body">
                            您的简历尚未完善,请先完善您的个人简历以便更好的接受我们的服务!
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-primary to-resume">确定</button>
                        </div>
                    </div>
                </div>
            </div>
        <!--resumeModal E-->
    </div>
</div>

@section('js')
<script src="/js/bootstrap-datetimepicker.min.js"></script>
<script>
	$.fn.datetimepicker.dates['zh-CN'] = {
        days: ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期日"],
        daysShort: ["周日", "周一", "周二", "周三", "周四", "周五", "周六", "周日"],
        daysMin:  ["日", "一", "二", "三", "四", "五", "六", "日"],
        months: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],
        monthsShort: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],
        today: "今天",
        suffix: [],
        meridiem: ["上午", "下午"]
    };
    $('.date-input').datetimepicker({
        weekStart: 1,
        todayBtn: 1,
        autoclose: 1,
        todayHighlight: 1,
        startView: 2,
        minView: 3,
        forceParse: 0,
        format: 'yyyy-mm-dd',
		language:"zh-CN",
		startDate: new Date()
    });
    $.extend({
        tab:function(target){
            $(".section-tab").delay(100).fadeOut(100);
            $("."+target).delay(100).fadeIn(100);
			$(".sec-right").html("");
        },
        _process:function (target, index) {
            $(".company").delay(100).fadeOut(100);
            $(".company."+target).delay(100).fadeIn(100);
        }
    });
    $(function () {
		var _search = location.search;
		var userid = (_search == "" ? $("#userid").val() : _search.split("=")[1] );
		if(location.hash!=""){
            setTimeout(function(){
                $(location.hash).trigger("click");
                location.hash="";
            },1000);
		}else{
			$(".interview-work").show();
		}
		//下拉列表
        $(document).on("click",".t-dropdown",function () {
            var direct = $(this).attr("data-direct");
            var iClass = direct == 1 ? 'icon-xia' : 'icon-you';
            var cDirect = direct == 1 ? "2" : "1";
            $(this).attr("data-direct", cDirect).next().stop().slideToggle();
            $(this).find("i").attr("class", "iconfont fr " + iClass);
		});
		//面试邀请，待面试，面试结果的信息获取
        $(".tab").click(function () {
			var target = $(this).attr("data-target1"),
				url    = $(this).attr("data-url"),
				_token = $("#_token").val(),
				mark   = $(this).attr("data-mark");
            $(".tab").removeClass("active");
            $(this).addClass("active");
            if(target == "interview"){
                var dealHtml 	   = '',//已处理
					ndealHtml	   = '',//未处理
					interviewHtml1 = '',//面试
					interviewHtml2 = '',//待面试
					interviewHtml3 = '',//面试
					passHtml 	   = '',//接受offer
					npassHtml	   = '',//不合适
					apassHtml	   = '';//收到offer	
				$.ajax({
					url:url,
					type:"get",
					dataType:"json",
					data:{
						_token:_token,
						userid:userid
					},
					success:function(data){
						//面试邀请
						if(mark == 'invit'){
							for(var i = 0, len = data.notacc.length;i<len;i++){
								dealHtml +=
                        	'<div class="list">'+
                            	'<div class="company-name process" data-id="'+data.notacc[i].invitid+'">'+
                                	'<div class="company-logo fl"><img src="'+data.notacc[i].company_avatar_url+'" alt=""></div>'+
                                	'<div class="introduce">'+
                                    	'<div class="name">'+data.notacc[i].company_name+'</div>'+
                                    	'<div class="pos">'+data.notacc[i].title+'</div>'+
                                    	'<div class="salary">'+data.notacc[i].salary+'</div>'+
                                	'</div>'+
                                	'<i class="iconfont icon-new red"></i>'+
									'<span class="badge">'+(data.notacc[i].notread==0 ? "":data.notacc[i].notread)+'</span>'+
                            	'</div>'+
                       		 '</div>';
							}
							ndealHtml = fillHtml(data.acc);
				
							$(".sec-left").html(
                    			'<div class="head">'+
                        			'<div class="head-title t-dropdown" data-direct="1">未处理<i class="iconfont icon-you fr"></i></div>'+
                        			'<div class="list-wrap">'+
                            			dealHtml+
                        			'</div>'+
                    			'</div>'+
                    			'<div class="head">'+
                        			'<div class="head-title t-dropdown" data-direct="1">已处理<i class="iconfont icon-you fr"></i></div>'+
                        			'<div class="list-wrap">'+
                            			ndealHtml+
                         			'</div>'+
                    			'</div>');
						}else if(mark == "interview"){
							interviewHtml1 = fillHtml(data.before);		
							interviewHtml2 = fillHtml(data.in);
							interviewHtml3 = fillHtml(data.after);
							$(".sec-left").html(
								'<div class="head">'+
                        			'<div class="head-title t-dropdown" data-direct="1">未定时间<i class="iconfont icon-you fr"></i></div>'+
                        			'<div class="list-wrap">'+
                            			interviewHtml1+
                        			'</div>'+
                    			'</div>'+
                    			'<div class="head">'+
                        			'<div class="head-title t-dropdown" data-direct="1">待面试<i class="iconfont icon-you fr"></i></div>'+
                        			'<div class="list-wrap">'+
                            			interviewHtml2+
                         			'</div>'+
                    			'</div>'+
								'<div class="head">'+
                        			'<div class="head-title t-dropdown" data-direct="1">已面试等反馈<i class="iconfont icon-you fr"></i></div>'+
                        			'<div class="list-wrap">'+
                            			interviewHtml3+
                         			'</div>'+
                    			'</div>');
							
						}else{
							passHtml  = fillHtml(data.suit);		
							npassHtml = fillHtml(data.notsuit);
							apassHtml = fillHtml(data.in);
							$(".sec-left").html(
								'<div class="head">'+
                        			'<div class="head-title t-dropdown" data-direct="1">面试通过<i class="iconfont icon-you fr"></i></div>'+
                        			'<div class="list-wrap">'+
                            			passHtml+
                        			'</div>'+
                    			'</div>'+
                    			'<div class="head">'+
                        			'<div class="head-title t-dropdown" data-direct="1">待接受<i class="iconfont icon-you fr"></i></div>'+
                        			'<div class="list-wrap">'+
                            			apassHtml+
                         			'</div>'+
                    			'</div>'+
								'<div class="head">'+
                        			'<div class="head-title t-dropdown" data-direct="1">不合适<i class="iconfont icon-you fr"></i></div>'+
                        			'<div class="list-wrap">'+
                            			npassHtml+
                         			'</div>'+
                    			'</div>');
						}

					}
				}) 
            }
			$.tab(target);
        });
        $(document).on("click",".company-name",function () {
            var _class = $(this).attr("class").split(" ")[1],
				index  = $(this).parent().index(),
				id	   = $(this).attr("data-id");	
            $(".list").removeClass("selected");
            $(this).parent().addClass("selected");
			$.ajax({
				url:"/talent/invitdata",
				type:"get",
				dataType:"json",
				data:{
					_token:$("#_token").val(),
					invitid:id,
					userid:userid
				},
				success:function(data){
					//data.company_tags.length = 10;
					//福利标签					
					var tag = data.jobdata.company_tags.map(function(v,n){
								return ('<li class="inline">'+v+'</li>')
							}).join("");
					//未处理有俩按钮
					var btnSec = data.jobdata.status == 1 ? '<div class="consult">'+
                            '<a href="javascript:;" data-infoid="'+data.messages[0].id+'" data-invitid="'+data.jobdata.invitid+'" data-status="210" class="interview inline accept">接受</a>'+
                            '<a href="javascript:;" data-infoid="'+data.messages[0].id+'" data-invitid="'+data.jobdata.invitid+'" data-status="20" class="interview inline refuse">拒绝</a>'+
							'</div>' : 
						'<section class="company-sec">'+
                            '<textarea placeholder="在这里与千里码官方发起对话"></textarea>'+
                            '<div class="response" data-sendid="'+data.messages[0].senderid+'" data-receiverid="'+data.messages[0].receiverid+'" data-invitid="'+data.jobdata.invitid+'" data-self="'+data.jobdata.isself+'">发送信息</div>'+
                        '</section>';
					//聊天列表 status>=0 是type内容做特殊处理 其余为普通chat content
					var chatInfo = 
						'<section class="company-sec chat-card-list">'+
							data.messages.map(function(v){
								return (
									'<div class="chat-card">'+
                                		'<div class="chat-top">'+
                                    		'<div class="avatar fl">'+
                                        		'<img src="'+v.avatar_file_name+'" alt="'+v.name+'的头像">'+
                                    		'</div>'+
                                    		'<div class="chat-title">'+
                                        		'<span class="name fl">'+v.name+'</span>'+
                                        		'<span class="time fr">'+v.created_at+'</span>'+
                                        		'<br/>'+
                                        		'<div class="chat-type">'+(v.status !== -1 ? v.content : "")+'</div>'+
                                    		'</div>'+
                                		'</div>'+
                                		'<div class="chat-content">'+(v.status !== -1 ? "" : v.content)+'</div>'+
										(v.status==2120 && v.isdone == 0 ?
										'<div class="consult">'+
                            				'<a href="javascript:;" data-infoid="'+v.id+'" data-invitid="'+data.jobdata.invitid+'" data-status="2121" class="interview inline accept-offer">接受offer</a>'+
                            				'<a href="javascript:;" data-infoid="'+v.id+'" data-invitid="'+data.jobdata.invitid+'" data-status="2122" class="interview inline refuse-offer">拒绝offer</a>'+
                        				'</div>' :
										"")+	
                            		'</div>'
								)
							}).join("")+
						'</section>';
					var companyInfo = '<div class="company ">'+
						'<div class="company-intro">'+
							'<div class="company-logo inline">'+
								'<img src="'+data.jobdata.company_avatar_url+'" alt="">'+
							'</div>'+
							'<div class="company-detail inline">'+
								'<h2>'+data.jobdata.company_name+'</h2>'+
								'<div class="domain inline"><i class="iconfont icon-xingye"></i>'+data.jobdata.company_industry+'</div>'+
								'<div class="scale inline"><i class="iconfont icon-guimo"></i>'+data.jobdata.company_size+'</div>'+
								'<br>'+
								'<div class="financing inline"><i class="iconfont icon-rongz"></i>'+data.jobdata.company_foundation+'</div>'+
								'<div class="place inline"><i class="iconfont icon-dizhi"></i>'+data.jobdata.company_location+'</div>'+
							'</div>'+
						'</div>'+
						'<section class="company-sec">'+
							'<div class="work"><span class="equal">职位:</span> '+data.jobdata.title+'</div>'+
							'<div class="salary"><span class="equal">薪资:</span> ['+data.jobdata.salary+']</div>'+
							'<div class="job-info"><span class="equal">职位介绍:</span>'+
								'<div class="info">'+
									data.jobdata.desc+
								'</div>'+
							'</div>'+
						'</section>'+
						'<section class="company-sec">'+
							'<div class="about"><span class="equal">公司简介</span></div>'+
							'<div class="info">'+
								data.jobdata.company_introduction+
							'</div>'+
							'<div class="tag"><span class="equal">福利标签</span></div>'+
							'<div class="tag-list info">'+
								'<ul>'+
									tag+	
								'</ul>'+
							'</div>'+
						'</section>'+
							chatInfo+
							btnSec +
					'</div>';
					$(".sec-right").html(companyInfo);
				}
			})
            $._process(_class,index);
        });
		//接受或拒绝（含邀请跟offer）
		$(document).on("click",".accept,.refuse,.accept-offer,.refuse-offer",function(){
			var status = $(this).attr("data-status"),
				invitid= $(this).attr("data-invitid"),
				infoid = $(this).attr("data-infoid");
			$.ajax({
				url:"/talent/acc",
				type:"get",
				dataType:"json",
				data:{
					_token:$("#_token").val(),
					status:status,
					invitid:invitid,
					infoid:infoid,
					userid:userid
				},
				success:function(data){
					if(data.acc){
						$("a.tab.active").trigger("click");
						$(".sec-right").html("");
						$(".invit .res").html(data.not_cnt+'/'+data.all_cnt);
						$(".interview .res").html(data.interview_cnt);
					}
				}
			})
		});
		//发送信息
		$(document).on("click",".response",function(){
			var msg		   = $("textarea").val(),
				isself	   = $(this).attr("data-self"),
				sendid	   = isself == 'true' ? $(this).attr("data-receiverid") : $(this).attr("data-sendid"),
				receiverid = isself == 'true' ? $(this).attr("data-sendid") : $(this).attr("data-receiverid"),
				invitid	   = $(this).attr("data-invitid")
			if(msg==""){
				return !1;
			}else{
				$.ajax({
					url:"/talent/info",
					type:"get",
					dataType:"json",
					data:{
						_token:$("#_token").val(),
						senderid:sendid,
						receiverid:receiverid,
						invitid:invitid,
						content:msg,
						userid:userid
					},
					success:function(data){
						var insertHtml = '';
						insertHtml+='<div class="chat-card">'+
                                		'<div class="chat-top">'+
                                    		'<div class="avatar fl">'+
                                        		'<img src="'+data.data.avatar_file_name+'" alt="">'+
                                    		'</div>'+
                                    		'<div class="chat-title">'+
                                        		'<span class="name fl">'+data.data.name+'</span>'+
                                        		'<span class="time fr">'+data.data.created_at+'</span>'+
                                        		'<br/>'+
                                        		'<div class="chat-type"></div>'+
                                    		'</div>'+
                                		'</div>'+
                                		'<div class="chat-content">'+data.data.content+'</div>'+
                            		'</div>';
						$(".chat-card-list").append(insertHtml);
						$("textarea").val("");
					}
				})
			}
		});

		//to resume
		$(".to-resume").click(function(){
			location.href="/talent/preview";
		})
		function fillHtml(data){
			var html = "";
			for(var w = 0, wlen = data.length;w<wlen;w++){
				html +=
                     '<div class="list">'+
                          '<div class="company-name process" data-id="'+data[w].invitid+'">'+
                              '<div class="company-logo fl"><img src="'+data[w].company_avatar_url+'" alt=""></div>'+
                              '<div class="introduce">'+
                                  '<div class="name">'+data[w].company_name+'</div>'+
                                  '<div class="pos">'+data[w].title+'</div>'+
                                  '<div class="salary">'+data[w].salary+'</div>'+
                              '</div>'+
							  '<span class="badge">'+(data[w].not_read==0 ? "" :data[w].not_read)+'</span>'+
                              '<div class="addition-info">'+data[w].statusstr+'</div>'+
                          '</div>'+
                      '</div>';				
			}
			return html;
		}


    })
</script>
@endsection
@endsection
